﻿Imports System.Data.SqlClient
Public Class SuaNguoiDung

    Private Sub SuaNguoiDung_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = Ketnoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        cmd.CommandText = "SELECT* FROM NGUOIDUNG WHERE UserName='" + Tendangnhap + "' and Password='" + MatKhau() + "'"
        Dim rd As SqlDataReader
        rd = cmd.ExecuteReader()
        Dim td As DataTable = New DataTable()
        td.Load(rd)
        Me.txtTenDangNhap.Text = td.Rows(0)(0).ToString()
        Me.txtMatKhau.Text = td.Rows(0)(1).ToString()
        Me.txtQuyenHan.Text = td.Rows(0)(2).ToString()
        con.Close()
    End Sub

    Private Sub btnSua_Click(sender As System.Object, e As System.EventArgs) Handles btnSua.Click
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = Ketnoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        cmd.CommandText = "UPDATE NGUOIDUNG SET QuyenHan='" + txtQuyenHan.Text + "' WHERE TenDangNhap='" + txtTenDangNhap.Text + "' AND MatKhau='" + txtMatKhau.Text + "'"
        Dim result As DialogResult
        result = MessageBox.Show("Bạn Có Muốn Thay Đổi Thông Tin Không?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If result = DialogResult.Yes Then
            cmd.ExecuteNonQuery()
            con.Close()
            MessageBox.Show("Sửa Thông Tin Thành Công")
            Me.Close()
            Dim frm As New DangNhapNguoiDung()
            frm.Show()
        End If
    End Sub

    Private Sub btnThoat_Click(sender As System.Object, e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
        Dim frm As New DangNhapNguoiDung()
        frm.Show()

    End Sub

    Private Function MatKhau() As Object
        Throw New NotImplementedException
    End Function

    Private Function Tendangnhap() As String
        Throw New NotImplementedException
    End Function

End Class